package com.example.common.base;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.example.common.mvp.IBasePresenter;
import com.example.common.mvp.IBaseView;

/**
 * @author skygge
 * @date 2020/7/30.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：包含Presenter层的基类
 */
public class BasePresentActivity<T extends IBasePresenter, B extends ViewDataBinding> extends BaseActivity implements IBaseView{

    protected T mPresent;
    protected B mDBind;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        mDBind = DataBindingUtil.setContentView(this, getLayoutId());
        initialization();
    }

    @Override
    protected void bindPresent() {
        super.bindPresent();
        initPresent();
        attachView();
    }

    /**
     * 初始化Presenter
     */
    protected void initPresent() {

    }

    private void attachView(){
        if (mPresent!=null){
            mPresent.attachView(this);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresent!=null){
            mPresent.detachView();
        }
    }
}
